package com.karaku.karaku_collector.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.karaku.karaku_collector.R;
import com.karaku.karaku_collector.common.binder.BindView;
import com.karaku.karaku_collector.common.binder.OnClick;
import com.karaku.karaku_collector.common.binder.UIBinder;

/**
 * Created by guopi on 2017/10/28 0028.
 */

@BindView(R.layout.view_confirm)
public class ConfirmView extends FrameLayout {

    @BindView(R.id.tv_content)
    private TextView tvContent;

    private Runnable callback;

    public ConfirmView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        UIBinder.bind(this, this, true);

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                setVisibility(View.GONE);
            }
        });
    }

    public void show(String content, Runnable okCallback) {
        tvContent.setText(content);
        this.callback = okCallback;
        setVisibility(VISIBLE);
    }

    public void hide() {
        callback = null;
        setVisibility(GONE);
    }

    @OnClick(R.id.btn_ok)
    private void ok() {
        if (callback != null) {
            callback.run();
        }
        hide();
    }


}
